package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.GoodsTypeVo;
import com.atguigu.jxc.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author nzmxfan
 * @create 2021-09-03-23:07
 */
@RestController
public class GoodsTypeController {

    @Autowired
    GoodsTypeService goodsTypeService;

    /**
     * 查询商品所有分类
     * @return
     */
    
    @PostMapping("/goodsType/loadGoodsType")
    public String loadGoodsType(){
        String str = goodsTypeService.loadGoodsType();
        System.out.println("str = " + str);
        return str;
    }

    /**
     * 添加分类
     * @param goodsTypeName
     * @param pId
     * @return
     */
    @PostMapping("/goodsType/save")
    public ServiceVO save(String goodsTypeName, Integer pId){
        goodsTypeService.save(goodsTypeName, pId);
        return new ServiceVO(100, "请求成功", null);
    }

    /**
     * 删除分类
     * @param goodsTypeId
     * @return
     */
    @PostMapping("/goodsType/delete")
    public ServiceVO deleteByGoodsTypeId(Integer goodsTypeId){

        goodsTypeService.deleteByGoodsTypeId(goodsTypeId);
        return new ServiceVO(100, "请求成功", null);
    }
}
